package com.lkk.cg.action;

import com.lkk.cg.base.BaseAction;
import com.lkk.cg.domain.Article;
import com.opensymphony.xwork2.ActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * Created by lkk on 2014/11/25.
 */
@Controller("indexAction")
@Scope("prototype")
public class IndexAction extends BaseAction<Article> {

    @Override
    public String execute() throws Exception {

        long todayPostCount = articleService.countTodayPost();
        long todayDownloadCount = dailyStatisticsService.countTodayDownload();
        long totalPostCount = articleService.countTotalPost();
        long totalDownloadCount = dailyStatisticsService.countTotalDownload();

        List<Article> mostDownloadArticles = articleService.getMostDownload();
        List<Article> lastedAddedArticles = articleService.getLastedAdded();

        ActionContext.getContext().put("todayPostCount",    todayPostCount);
        ActionContext.getContext().put("todayDownloadCount", todayDownloadCount);
        ActionContext.getContext().put("totalPostCount",     totalPostCount);
        ActionContext.getContext().put("totalDownloadCount", totalDownloadCount);

        ActionContext.getContext().put("mostDownloadArticles", mostDownloadArticles);
        ActionContext.getContext().put("lastedAddedArticles", lastedAddedArticles);

        return SUCCESS;
    }
}
